package com.central.oauth.config;

import com.central.common.constant.ExtendConstant;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Base64Utils;

/**
 * @program: central-platform
 * @author: lishuai
 * @create: 2022-02-08 20:36
 * 备注：只加在需要发起feign调用的客户端
 */
@Configuration
public class FeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
        //添加token
        byte[] token = Base64Utils.encode(ExtendConstant.backend_access_token.getBytes());
        requestTemplate.header(ExtendConstant.backend_access_token, new String(token));
    }
}
